package com.supplychain.scm.core.oss.util;

import com.amazonaws.util.IOUtils;

import java.io.*;

/**
 * @author DayDayUp
 * @datetime 2023-11-01 12:49
 **/
public class StreamUtil {
    static final String PREFIX = "stream2file";//前缀字符串定义文件名；必须至少三个字符
    static final String SUFFIX = ".tmp";//后缀字符串定义文件的扩展名；如果为null，则将使用后缀".tmp"
    public static File stream2file (InputStream in) throws IOException {
        final File tempFile = File.createTempFile(PREFIX, SUFFIX);
        tempFile.deleteOnExit();
        try (FileOutputStream out = new FileOutputStream(tempFile)) {
            IOUtils.copy(in, out);
        }
        return tempFile;
    }
}
